package com.sample.wanandroidx.ui.fragment

import android.view.View
import com.just.agentweb.AgentWebConfig
import com.sample.library.WebActivity
import com.sample.library.cookie.CookieManager
import com.sample.library.ext.startActivity
import com.sample.library.util.ToastUtil
import com.sample.wanandroidx.app.App
import com.sample.wanandroidx.basic.BaseMvvmFragment
import com.sample.wanandroidx.databinding.FragmentUserBinding
import com.sample.wanandroidx.model.UserModel
import com.sample.wanandroidx.support.Urls
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull

class UserFragment : BaseMvvmFragment<FragmentUserBinding, UserModel>(FragmentUserBinding::inflate) {

    override fun initLazyLoad() {
    }

    override fun onRightClick(v: View?) {
        if (App.user == null) {
            ToastUtil.show("请先登录!")
            return
        }
        Urls.baseUrl.toHttpUrlOrNull()?.let {
            val cookies = CookieManager.getInstance(activity?.application).loadForRequest(it)
            cookies.forEach { cookie ->
                AgentWebConfig.syncCookie(Urls.baseUrl, cookie.toString());
            }
            startActivity<WebActivity>("url" to Urls.user_article_add_url, "title" to "分享文章")
        }
    }

    override fun initialization() {

    }

    private fun setCoinData() {
    }

}








